package com.yk.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yk.common.annotation.Log;
import com.yk.common.enums.BusinessType;
import com.yk.system.domain.SysChild;
import com.yk.system.service.ISysChildService;
import com.yk.common.core.controller.BaseController;
import com.yk.common.core.domain.AjaxResult;
import com.yk.common.utils.poi.ExcelUtil;
import com.yk.common.core.page.TableDataInfo;

/**
 * 孩子信息Controller
 * 
 * @author xufei
 * @date 2025-04-28
 */
@Controller
@RequestMapping("/system/child")
public class SysChildController extends BaseController
{
    private String prefix = "system/child";

    @Autowired
    private ISysChildService sysChildService;

    @RequiresPermissions("system:child:view")
    @GetMapping()
    public String child()
    {
        return prefix + "/child";
    }

    /**
     * 查询孩子信息列表
     */
    @RequiresPermissions("system:child:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysChild sysChild)
    {
        startPage();
        List<SysChild> list = sysChildService.selectSysChildList(sysChild);
        return getDataTable(list);
    }

    /**
     * 导出孩子信息列表
     */
    @RequiresPermissions("system:child:export")
    @Log(title = "孩子信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysChild sysChild)
    {
        List<SysChild> list = sysChildService.selectSysChildList(sysChild);
        ExcelUtil<SysChild> util = new ExcelUtil<SysChild>(SysChild.class);
        return util.exportExcel(list, "孩子信息数据");
    }

    /**
     * 新增孩子信息
     */
    @RequiresPermissions("system:child:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存孩子信息
     */
    @RequiresPermissions("system:child:add")
    @Log(title = "孩子信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysChild sysChild)
    {
        return toAjax(sysChildService.insertSysChild(sysChild));
    }

    /**
     * 修改孩子信息
     */
    @RequiresPermissions("system:child:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysChild sysChild = sysChildService.selectSysChildById(id);
        mmap.put("sysChild", sysChild);
        return prefix + "/edit";
    }

    /**
     * 修改保存孩子信息
     */
    @RequiresPermissions("system:child:edit")
    @Log(title = "孩子信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysChild sysChild)
    {
        return toAjax(sysChildService.updateSysChild(sysChild));
    }

    /**
     * 删除孩子信息
     */
    @RequiresPermissions("system:child:remove")
    @Log(title = "孩子信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysChildService.deleteSysChildByIds(ids));
    }
}
